import {
  Get,
  Controller,
  Post,
  UseFilters,
  Body,
  Param,
  ParseIntPipe,
  Res,
  HttpException,
  HttpStatus,
  UseInterceptors,
} from '@nestjs/common';
import { Response } from 'express';
import { CatsService } from './cats.service';
import { HttpExceptionFilter } from '../common/filter/http-exception.filter';
import { CreateCatDto } from './dto/create-cat.dto';
import { LoggingInterceptor } from '../common/interceptor/logging.interceptor';
import { ErrorsInterceptor } from '../common/interceptor/error.interceptor';

@Controller('cats')
@UseInterceptors(ErrorsInterceptor)
export class CatsController {
  constructor(private readonly catsService: CatsService) {}

  @Get()
  @UseFilters(new HttpExceptionFilter())
  findAll(@Res() res: Response) {
    // return res.json(this.catsService.findAll());
    throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
  }

  @Post()
  @UseFilters(new HttpExceptionFilter())
  async create(@Body() createCatDto: CreateCatDto, @Res() res: Response) {
    this.catsService.create({ ...createCatDto, breed: 'bwm' });
    res.json({ success: true });
    return;
  }

  @Get(':id')
  @UseInterceptors(LoggingInterceptor)
  async findOne(@Param('id', ParseIntPipe) id: number, @Res() res: Response) {
    // res.redirect(
    //   'https://sitecdn.zcycdn.com/f2e-assets/b0c6dca7-870b-4c98-8a19-257eb08b4ad9.xlsx',
    // );
    res.json({ a: 1 });
    return;
  }
}
